package com.second.app.thread.volatiled;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @Author GYZ
 * <pre>
 *
 * </pre>
 */
public class AddCountDemo {

    public static void main(String[] args) {

//        AtomicInteger atomicInteger = new AtomicInteger(0);
//        for (int i = 0; i < 10000; i++) {
//            new Thread(() -> {
//                atomicInteger.incrementAndGet();
//                System.out.println(atomicInteger.get());
//            }).start();
//        }
        AtomicLong aiRef = new AtomicLong();
        CountDownLatch countDownLatch = new CountDownLatch(5);
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                System.out.println("线程:" + Thread.currentThread().getName() + "，加了100之后的值为：" + aiRef.addAndGet(100));
                aiRef.addAndGet(1);
                countDownLatch.countDown();
            }, "线程" + i).start();
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("aiRef :" + aiRef.get());


    }
}
